package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.MycastListPost;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/11/21.
 */
public class MyCastAdapter extends ArrayAdapter<MycastListPost.MycastEntity> {

    private Context context;
    private LayoutInflater layoutInflater;

    public MyCastAdapter(Context context, List<MycastListPost.MycastEntity> lists) {
        super(context, 0, lists);

        this.context = context;

        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MycastListPost.MycastEntity mycastEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_mycast_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        GlideLoader.getInstance().get(context, mycastEntity.picurl, viewHolder.item_mycast_list_iv, R.mipmap.img_holder, GlideLoader.TYPE_IMAGE_FILLET);
        viewHolder.item_mycast_list_date_tv.setText(mycastEntity.time);
        viewHolder.item_mycast_list_material_tv.setText(mycastEntity.title);
        viewHolder.item_mycast_list_price_tv.setText(mycastEntity.price + "/" + mycastEntity.name);
        viewHolder.item_mycast_list_count_tv.setText(mycastEntity.num + mycastEntity.name);
        viewHolder.item_mycast_list_total_price_tv.setText(mycastEntity.total);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_mycast_list_date_tv) private TextView item_mycast_list_date_tv;
        @BoundView(R.id.item_mycast_list_iv) private ImageView item_mycast_list_iv;
        @BoundView(R.id.item_mycast_list_material_tv) private TextView item_mycast_list_material_tv;
        @BoundView(R.id.item_mycast_list_price_tv) private TextView item_mycast_list_price_tv;
        @BoundView(R.id.item_mycast_list_count_tv) private TextView item_mycast_list_count_tv;
        @BoundView(R.id.item_mycast_list_total_price_tv) private TextView item_mycast_list_total_price_tv;
    }

}
